package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark85Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark85 extends BaseMark {

    LayoutWatermark85Binding binding;

    public Mark85(@NonNull Context context) {
        super(context);
    }

    public Mark85(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark85(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark85Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark85Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.item74Title, "title85", binding.item74Title);
        setText(binding.item74Time, "time85");
        setTime(binding.item74Time, new SimpleDateFormat("HH:mm"));
        setTime(binding.item74Date, new SimpleDateFormat("yyyy.MM.dd"));
        setWeek(binding.item74Week);

        setText(binding.item74Address, "didian85", binding.item74Address);
        setText(binding.item74Lalo, "jingwei85", binding.item74Lalo);
        setText(binding.item74Operator, "operator85", binding.item74Operator);


        setText(binding.item74Remark, "beizhu85", binding.item74Remark);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title85", "标题"));
        list.add(new EditItem("time85", "时间", true));
        list.add(new EditItem("didian85", "地点"));
        list.add(new EditItem("jingwei85", "经纬度"));
        list.add(new EditItem("operator85", "操作员"));
        list.add(new EditItem("beizhu85", "备注"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.item74Time, new SimpleDateFormat("HH:mm"));
            setTime(binding.item74Date, new SimpleDateFormat("yyyy.MM.dd"));
            setWeek(binding.item74Week);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (item.show) {
                showView(binding.item74Time, binding.item74Date, binding.item74Week, binding.item74Line);
            } else {
                hideView(binding.item74Time, binding.item74Date, binding.item74Week, binding.item74Line);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
